/*
	clang++ ./object/typeobject.cpp ./object/object.cpp ./object/error.cpp ./object/string.cpp ./object/array.cpp ./object/list.cpp ./object/number.cpp ./core/read.cpp ../test/read_t.cpp
*/
#include "../include/object/error.hpp"
namespace malt
{

Object *m_read(FILE *stream = stdin);
Object *__read__(FILE *stream = stdin);

inline void print_malt_info()
{
	printf("\e[1m\n\
           _ _   _     |  Malt Lisp Core v0.1.1\n\
 _ _______(_) |_| |_   |  Malt Lisp Repl v0.2\n\
| '_   _  \\ | |_   _|  |  Github Address: https://github.com/Index-Flandre/Malt.git\n\
| | | | | | | | | |__  |  Email: enterindex@gmail.com\n\
\\_| |_| |_|_|_| |___/  |  Target: x86_64-linux-gnu\e[0m\n\n");
}

extern bool is_repl_mode;

int main()
{
	print_malt_info();
	ErrorInit();
	TypeInit();
	is_repl_mode = true;
	for (;;)
	{
		try
		{
			printf("malt> ");
			Object *obj = __read__();
			if (!(obj == MaltNullptr))
				obj->repl_print();
		}
		catch (...)
		{
			if (merrno != MaltNullptr)
			{
				merrno->repl_print();
				merrno = (Error *)MaltNullptr;
			}
			else
			{
				RuntimeError.repl_print();
			}
		}
		printf("\n");
	}
	return 0;
}
}

int main()
{
	malt::main();
	return 0;
}